﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KP_CommonLibrary.KP_CommonControls;
using KP_CommonLibrary.KP_ObjectReferences;

namespace KEEPER_BRR_13dotNET.Presentation
{
    public partial class FrmLogin : KP_FormBase01
    {
        public FrmLogin()
        {
            InitializeComponent();
        }
        private void KP_BtnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void KP_BtnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                KPMessageBox.Show("Chưa gõ Tên đăng nhập", "Chú ý", KPMessageBoxButton.OK, KPMessageBoxIcon.Warning);
                txtUserName.Focus();
                return;
            }

            try
            {
                if (KP_CommonLibrary.KP_ObjectReferences.KP_OUser.Login(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
                {
                    this.DialogResult = DialogResult.OK;

                    //KP_CommonLibrary.KP_ObjectReferences.KP_OR_ConnectSql.Server_Name = "SRV-SERVER";
                    KP_CommonLibrary.KP_ObjectReferences.KP_OUser.User_Name = txtUserName.Text;
                    //KP_CommonLibrary.KP_ObjectReferences.KP_OR_ConnectSql.Server_DbName = "KEEPER SALES R14.NET";

                }
                else KPMessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng", "Lỗi đăng nhập", KPMessageBoxButton.OK, KPMessageBoxIcon.Warning);

            }
            catch (Exception ex)
            {
                KPMessageBox.Show("Lỗi: " + ex.Message, "Lỗi đăng nhập", KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
            }
            finally
            { }
        }
    }
}
